package cliente.gui;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.table.DefaultTableModel;

import br.ufpi.domain.Pergunta;
import br.ufpi.domain.Resposta;
import br.ufpi.domain.Usuario;
import java.awt.Component;
import javax.swing.JComponent;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;

import util.*;
import util.Datas.Datas;
import util.Datas.DatasMenorErrado;
import util.Datas.ExceptionDate;

/**
 *
 * @author aers
 */
/**
 * @author cleiton
 * 
 */
public class UsuarioGUI extends javax.swing.JFrame {

    private String hostname;
    private int porta;
    private List<Pergunta> perguntas;
    private List<Resposta> respostas;
    private Pergunta perguntaSendoUtilizada;
    private int linhaTabelaPerguntaSendoUtilizada = 0;
    private int linhaTabelaRespostaEmUso = 0;
    /** Creates new form UsuarioGUI */
    private String[] statusPergunta = {"Pendente", "Sem Resposta", "Respondida e Não Avaliada", "Respondida Corretamente", "Respondida Parcialmente", "Não Aceita"};
    private String[] statusResposta = {"Pendente", "Parcialmente Correta", "Coreta", "Incorreta"};
    private Usuario usuario;
    private ProtocoloMensagem protocoloMensagem;
    /**
     * Objeto que ira gerenciar quantas perguntas o kra que por vez. Neste
     * metodo ele ira informa a ultima pergunta de kda pagina da Tabela.
     */
    private int numeroInicio = 0;
    private static int numerodePerguntasRequeridas = 40;

    public UsuarioGUI(String matriculaUsuario, String hostname, int porta) {
        this.hostname = hostname;
        this.porta = porta;
        protocoloMensagem = new ProtocoloMensagem();
        iniciarUsuario(matriculaUsuario);
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(UsuarioGUI.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            Logger.getLogger(UsuarioGUI.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(UsuarioGUI.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedLookAndFeelException ex) {
            Logger.getLogger(UsuarioGUI.class.getName()).log(Level.SEVERE, null, ex);
        }

        initComponents();
        this.setLocationRelativeTo(null);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed"
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPopupMenu1 = new javax.swing.JPopupMenu();
        buttonGroup1 = new javax.swing.ButtonGroup();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jLabel18 = new javax.swing.JLabel();
        jtfEmail = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        jtfNome = new javax.swing.JTextField();
        jtfMatricula = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        jPanel8 = new javax.swing.JPanel();
        jFormattedTextField3 = new javax.swing.JFormattedTextField();
        jLabel24 = new javax.swing.JLabel();
        jLabel25 = new javax.swing.JLabel();
        jFormattedTextField4 = new javax.swing.JFormattedTextField();
        jLabel19 = new javax.swing.JLabel();
        jtfTotalPontos = new javax.swing.JTextField();
        jButton8 = new javax.swing.JButton();
        jrbPesquisarPorDate = new javax.swing.JRadioButton();
        jPanel9 = new javax.swing.JPanel();
        jcbRanking = new javax.swing.JComboBox();
        jScrollPane6 = new javax.swing.JScrollPane();
        jtbRanking = new javax.swing.JTable();
        jbtPesquisarRabking = new javax.swing.JButton();
        jftDateRanking = new javax.swing.JFormattedTextField();
        jLabel22 = new javax.swing.JLabel();
        jLabel23 = new javax.swing.JLabel();
        jftRankingDateFinal = new javax.swing.JFormattedTextField();
        jRadioButton1 = new javax.swing.JRadioButton();
        jPanel10 = new javax.swing.JPanel();
        jcbPerguntaOurResposta = new javax.swing.JComboBox();
        jcbCondicaoPerguntaResposta = new javax.swing.JComboBox();
        jButton6 = new javax.swing.JButton();
        jScrollPane7 = new javax.swing.JScrollPane();
        jtbMinhasPerguntasRespostas = new javax.swing.JTable();
        jPanel11 = new javax.swing.JPanel();
        jScrollPane8 = new javax.swing.JScrollPane();
        jtpPerguntaAba1 = new javax.swing.JTextPane();
        jScrollPane9 = new javax.swing.JScrollPane();
        jtpComentarioAba1 = new javax.swing.JTextPane();
        jLabel20 = new javax.swing.JLabel();
        jLabel21 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jLabel11 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jtMinhasPerguntas = new javax.swing.JTable();
        jcbPergunta = new javax.swing.JComboBox();
        jLabel12 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jtResposta = new javax.swing.JTable();
        jLabel13 = new javax.swing.JLabel();
        jcbRespondidas = new javax.swing.JComboBox();
        jcbFrequencia = new javax.swing.JComboBox();
        jScrollPane4 = new javax.swing.JScrollPane();
        jtaResposta = new javax.swing.JTextPane();
        jLabel14 = new javax.swing.JLabel();
        jScrollPane5 = new javax.swing.JScrollPane();
        jtaPergunta = new javax.swing.JTextPane();
        jLabel15 = new javax.swing.JLabel();
        jbtResponder = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jPanel5 = new javax.swing.JPanel();
        jtfTitulo = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        btPerguntar = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel4 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtaEnviarPergunta = new javax.swing.JTextPane();
        jPanel2 = new javax.swing.JPanel();
        jPanel6 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jTextField7 = new javax.swing.JTextField();
        jTextField3 = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jTextField6 = new javax.swing.JTextField();
        jButton4 = new javax.swing.JButton();
        jPanel7 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        pfSenhaAntiga = new javax.swing.JPasswordField();
        jLabel9 = new javax.swing.JLabel();
        pfNovaSenha = new javax.swing.JPasswordField();
        jLabel10 = new javax.swing.JLabel();
        pfNovaSenhaRepita = new javax.swing.JPasswordField();
        btAlterarSenha = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("SISTEMA DE PERGUNTAS E RESPOSTAS");
        setBounds(new java.awt.Rectangle(400, 200, 800, 600));
        setResizable(false);

        jTabbedPane1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTabbedPane1MouseClicked(evt);
            }
        });
        jTabbedPane1.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jTabbedPane1StateChanged(evt);
            }
        });

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Minhas Informações"));

        jLabel18.setText("E-mail:");

        jtfEmail.setText(usuario.getEmail());
        jtfEmail.setEditable(false);

        jLabel17.setText("Nome:");

        jtfNome.setText(usuario.getNomeCompleto());
        jtfNome.setEditable(false);

        jtfMatricula.setText(usuario.getMatricula());
        jtfMatricula.setEditable(false);

        jLabel16.setText("Matricula:");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel16)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtfMatricula, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel17)
                            .addComponent(jLabel18))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jtfEmail)
                            .addComponent(jtfNome, javax.swing.GroupLayout.DEFAULT_SIZE, 509, Short.MAX_VALUE))))
                .addContainerGap(78, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel16)
                    .addComponent(jtfMatricula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel17)
                    .addComponent(jtfNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel18)
                    .addComponent(jtfEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jPanel8.setBorder(javax.swing.BorderFactory.createTitledBorder("Minha Pontuação"));

        try {
            jFormattedTextField3.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        jLabel24.setText("De:");

        jLabel25.setText("Até:");

        try {
            jFormattedTextField4.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        jLabel19.setText("Total de Pontos:");

        jtfTotalPontos.setEditable(false);

        jButton8.setText("Pesquisar");
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });

        jrbPesquisarPorDate.setSelected(true);
        jrbPesquisarPorDate.setText("Pesquisar por Data");
        jrbPesquisarPorDate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrbPesquisarPorDateActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel8Layout.createSequentialGroup()
                        .addComponent(jrbPesquisarPorDate)
                        .addGap(82, 82, 82)
                        .addComponent(jLabel24)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jFormattedTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel25)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jFormattedTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 39, Short.MAX_VALUE)
                        .addComponent(jButton8)
                        .addGap(29, 29, 29))
                    .addGroup(jPanel8Layout.createSequentialGroup()
                        .addComponent(jLabel19)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtfTotalPontos, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jFormattedTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel24)
                    .addComponent(jFormattedTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel25)
                    .addComponent(jButton8)
                    .addComponent(jrbPesquisarPorDate))
                .addGap(11, 11, 11)
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel19)
                    .addComponent(jtfTotalPontos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(18, Short.MAX_VALUE))
        );

        jPanel9.setBorder(javax.swing.BorderFactory.createTitledBorder("Raking"));

        jcbRanking.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Alunos", "Melhor Resposta" }));
        jcbRanking.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbRankingActionPerformed(evt);
            }
        });

        jtbRanking.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nome", "Pontuação"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane6.setViewportView(jtbRanking);

        jbtPesquisarRabking.setText("Pesquisar");
        jbtPesquisarRabking.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtPesquisarRabkingActionPerformed(evt);
            }
        });

        try {
            jftDateRanking.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        jLabel22.setText("De:");

        jLabel23.setText("Até:");

        try {
            jftRankingDateFinal.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        jRadioButton1.setSelected(true);
        jRadioButton1.setText("Pesquisar por data");
        jRadioButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
        jPanel9.setLayout(jPanel9Layout);
        jPanel9Layout.setHorizontalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane6, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 306, Short.MAX_VALUE)
                    .addComponent(jRadioButton1)
                    .addComponent(jcbRanking, 0, 306, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel9Layout.createSequentialGroup()
                        .addComponent(jLabel22)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jftDateRanking, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel23)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jftRankingDateFinal, javax.swing.GroupLayout.DEFAULT_SIZE, 83, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(jbtPesquisarRabking)))
                .addContainerGap())
        );
        jPanel9Layout.setVerticalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addComponent(jcbRanking, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jRadioButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel22)
                        .addComponent(jftDateRanking, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jbtPesquisarRabking)
                    .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jftRankingDateFinal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel23)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane6, javax.swing.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE))
        );

        jPanel10.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        jcbPerguntaOurResposta.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Perguntas", "Respostas" }));
        jcbPerguntaOurResposta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbPerguntaOurRespostaActionPerformed(evt);
            }
        });

        jcbCondicaoPerguntaResposta.setModel(new javax.swing.DefaultComboBoxModel(statusPergunta));

        jButton6.setText("Pesquisar");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        jtbMinhasPerguntasRespostas.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Assunto", "Pergunta", "Comentário"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jtbMinhasPerguntasRespostas.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jtbMinhasPerguntasRespostasMouseClicked(evt);
            }
        });
        jtbMinhasPerguntasRespostas.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jtbMinhasPerguntasRespostasKeyReleased(evt);
            }
        });
        jScrollPane7.setViewportView(jtbMinhasPerguntasRespostas);

        jtpPerguntaAba1.setEditable(false);
        jScrollPane8.setViewportView(jtpPerguntaAba1);

        jtpComentarioAba1.setEditable(false);
        jScrollPane9.setViewportView(jtpComentarioAba1);

        jLabel20.setText("Pergunta:");

        jLabel21.setText("Comentários");

        javax.swing.GroupLayout jPanel11Layout = new javax.swing.GroupLayout(jPanel11);
        jPanel11.setLayout(jPanel11Layout);
        jPanel11Layout.setHorizontalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel11Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane8, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 367, Short.MAX_VALUE)
                    .addComponent(jScrollPane9, javax.swing.GroupLayout.DEFAULT_SIZE, 367, Short.MAX_VALUE)
                    .addComponent(jLabel20)
                    .addComponent(jLabel21))
                .addContainerGap())
        );
        jPanel11Layout.setVerticalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel11Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel20)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane9, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(2, 2, 2)
                .addComponent(jLabel21)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane8, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(52, 52, 52))
        );

        javax.swing.GroupLayout jPanel10Layout = new javax.swing.GroupLayout(jPanel10);
        jPanel10.setLayout(jPanel10Layout);
        jPanel10Layout.setHorizontalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel10Layout.createSequentialGroup()
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel10Layout.createSequentialGroup()
                        .addComponent(jcbPerguntaOurResposta, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jcbCondicaoPerguntaResposta, javax.swing.GroupLayout.PREFERRED_SIZE, 184, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 151, Short.MAX_VALUE)
                        .addComponent(jButton6))
                    .addComponent(jScrollPane7, javax.swing.GroupLayout.DEFAULT_SIZE, 586, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addComponent(jPanel11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jPanel10Layout.setVerticalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel10Layout.createSequentialGroup()
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton6)
                    .addComponent(jcbPerguntaOurResposta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jcbCondicaoPerguntaResposta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane7, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(47, 47, 47))
            .addGroup(jPanel10Layout.createSequentialGroup()
                .addComponent(jPanel11, javax.swing.GroupLayout.PREFERRED_SIZE, 204, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(35, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel10, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addComponent(jPanel9, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Tela inicial", jPanel1);

        jPanel3.setName("MinhasPerguntasRespostas"); // NOI18N

        jLabel11.setText("Perguntas");

        jtMinhasPerguntas.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Assunto", "Pergunta", "Status", "Aluno"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.Object.class, java.lang.Object.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jtMinhasPerguntas.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jtMinhasPerguntasMouseClicked(evt);
            }
        });
        jtMinhasPerguntas.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                botaoAtualizarResposta(evt);
            }
        });
        jScrollPane2.setViewportView(jtMinhasPerguntas);

        jcbPergunta.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Todas Perguntas", "Minhas Perguntas" }));
        jcbPergunta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbPerguntaActionPerformed(evt);
            }
        });

        jLabel12.setText("Classificar Perguntas:");

        jtResposta.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Resposta", "Status", "Usuario"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jtResposta.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jtRespostaMouseClicked(evt);
            }
        });
        jtResposta.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jtRespostaKeyReleased(evt);
            }
        });
        jScrollPane3.setViewportView(jtResposta);

        jLabel13.setText("Respostas:");

        jcbRespondidas.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Todas", "Respondidas", "Não Respondidas" }));

        jcbFrequencia.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Todas", "Hoje", "Semana", "Mês" }));

        jtaResposta.setEditable(false);
        jScrollPane4.setViewportView(jtaResposta);

        jLabel14.setText("Resposta:");

        jtaPergunta.setEditable(false);
        jScrollPane5.setViewportView(jtaPergunta);

        jLabel15.setText("Pergunta Selecionada");

        jbtResponder.setText("Responder pergunta");
        jbtResponder.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtResponderActionPerformed(evt);
            }
        });

        jButton5.setText("Buscar");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel11)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 429, Short.MAX_VALUE)
                        .addComponent(jLabel12)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jcbPergunta, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jcbRespondidas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jcbFrequencia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton5))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(jLabel15))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 1003, Short.MAX_VALUE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 1003, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel13)
                            .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 396, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addComponent(jLabel14)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 421, Short.MAX_VALUE)
                                .addComponent(jbtResponder))
                            .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 601, Short.MAX_VALUE))))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(jButton5)
                    .addComponent(jcbPergunta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel12)
                    .addComponent(jcbRespondidas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jcbFrequencia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(30, 30, 30)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel15))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(190, 190, 190)
                        .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(15, 15, 15)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel13)
                            .addComponent(jLabel14)))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbtResponder)))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jScrollPane3, 0, 0, Short.MAX_VALUE)
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 135, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Perguntas", jPanel3);

        jLabel1.setText("Assunto:");

        jLabel2.setText("Digite a sua pergunta:");

        btPerguntar.setText("Enviar pergunta");
        btPerguntar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btPerguntarActionPerformed(evt);
            }
        });

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel4.setText("Info: Sua pergunta só constará para ser  respondida pelos outros alunos depois que esta for aprovada pelo professor");

        jtaEnviarPergunta.setToolTipText("Digite aqui sua pergunta para ser analisada pelo professor.");
        jScrollPane1.setViewportView(jtaEnviarPergunta);

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 1013, Short.MAX_VALUE)
                    .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 1013, Short.MAX_VALUE)
                    .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel5Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 906, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jtfTitulo, javax.swing.GroupLayout.DEFAULT_SIZE, 1013, Short.MAX_VALUE)
                    .addComponent(btPerguntar))
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel4)
                .addGap(2, 2, 2)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jtfTitulo, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 222, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btPerguntar)
                .addGap(325, 325, 325))
        );

        jTabbedPane1.addTab("Enviar pergunta", jPanel5);

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder("Alterar informacoes gerais"));

        jLabel5.setText("Matricula");

        jTextField7.setText(usuario.getMatricula());
        jTextField7.setEditable(false);

        jTextField3.setText(usuario.getNomeCompleto());

        jLabel6.setText("Nome completo");

        jLabel8.setText("Email");

        jTextField6.setText(usuario.getEmail());

        jButton4.setText("Atualizar");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel5)
                    .addComponent(jLabel6)
                    .addComponent(jLabel8)
                    .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextField3, javax.swing.GroupLayout.DEFAULT_SIZE, 233, Short.MAX_VALUE)
                    .addComponent(jTextField6))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
                .addContainerGap(168, Short.MAX_VALUE)
                .addComponent(jButton4)
                .addContainerGap())
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButton4)
                .addContainerGap())
        );

        jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder("Alterar senha"));

        jLabel7.setText("Senha antiga");

        jLabel9.setText("Nova senha");

        jLabel10.setText("Repita nova senha");

        btAlterarSenha.setText("Atualizar");
        btAlterarSenha.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btAlterarSenhaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel7)
                    .addComponent(jLabel9)
                    .addComponent(pfNovaSenha)
                    .addComponent(jLabel10)
                    .addComponent(pfNovaSenhaRepita)
                    .addComponent(pfSenhaAntiga))
                .addContainerGap(31, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel7Layout.createSequentialGroup()
                .addContainerGap(46, Short.MAX_VALUE)
                .addComponent(btAlterarSenha)
                .addContainerGap())
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pfSenhaAntiga, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel9)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pfNovaSenha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel10)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pfNovaSenhaRepita, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btAlterarSenha)
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(22, 22, 22)
                .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(583, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel7, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(416, 416, 416))
        );

        jTabbedPane1.addTab("Meus Dados", jPanel2);

        jLabel3.setText("Logado como: "+usuario.getNomeCompleto());

        jButton1.setText("Logout");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Fechar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jTabbedPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 1028, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 790, Short.MAX_VALUE)
                        .addComponent(jButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton2)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 539, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 27, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jButton2)
                    .addComponent(jButton1))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

        private void jtMinhasPerguntasMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jtMinhasPerguntasMouseClicked
            DefaultTableModel tableResposta = (DefaultTableModel) jtResposta.getModel();
            jtaResposta.setText("");

            // Limpa a tabela
            // tableResposta.fireTableRowsDeleted(0, tableResposta.getRowCount());
            for (int i = tableResposta.getRowCount(); i > 0; i--) {
                tableResposta.removeRow(0);
            }
            perguntaSendoUtilizada = perguntas.get(jtMinhasPerguntas.getSelectedRow());
            jtaPergunta.setText(perguntaSendoUtilizada.getMensagem());
//Usuario não vai poder responder pergunta que não foi dele
            //|| perguntaSendoUtilizada.getUsuario().getNomeCompleto().equals(usuario.getNomeCompleto())
//Pergunta Respondida Corretamente
            if (perguntaSendoUtilizada.getStatus() == 3 || perguntaSendoUtilizada.getStatus() == 0) {
                jbtResponder.setEnabled(false);
            } else {
                jbtResponder.setEnabled(true);
            }
            ArrayList<Object> objetos = protocoloMensagem.decodificaRespostas(enviarReceberPergunta(protocoloMensagem.getRespostas(perguntaSendoUtilizada.getId(), usuario.getMatricula())));
            if (objetos != null) {
                respostas = (List<Resposta>) objetos.get(0);
                int maiorId = (Integer) objetos.get(1);
                int total = (Integer) objetos.get(2);
                for (Resposta resposta : respostas) {
                    Vector vector = new Vector();
                    vector.add(resposta.getMensagem());
                    vector.add(statusResposta[resposta.getStatus()]);
                    vector.add(resposta.getUsuario().getNomeCompleto());
                    tableResposta.addRow(vector);
                }
            }
            //TODO Implementar metodo para Protocolo getResposta da Pergunta
        }//GEN-LAST:event_jtMinhasPerguntasMouseClicked

        private void jtRespostaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jtRespostaMouseClicked
            DefaultTableModel tableResposta = (DefaultTableModel) jtResposta.getModel();
            jtaResposta.setText((String) tableResposta.getValueAt(jtResposta.getSelectedRow(), 0));
        }//GEN-LAST:event_jtRespostaMouseClicked

        private void jbtResponderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtResponderActionPerformed
            ResponderPerguntaGui responderPerguntaGui = new ResponderPerguntaGui(perguntaSendoUtilizada.getId().toString(), usuario.getMatricula(), perguntaSendoUtilizada.getMensagem(), hostname, porta);
            responderPerguntaGui.setVisible(true);
        }//GEN-LAST:event_jbtResponderActionPerformed

        private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
            atualizarTablaPergunta();
        }//GEN-LAST:event_jButton5ActionPerformed

        private void jcbPerguntaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbPerguntaActionPerformed
            System.out.println(jcbPergunta.getSelectedItem());
            if (jcbPergunta.getSelectedItem().equals("Minhas Perguntas")) {
                jcbRespondidas.addItem("Pendentes");
            } else {
                jcbRespondidas.removeItem("Pendentes");
                jcbRespondidas.setSelectedItem(0);
            }
        }//GEN-LAST:event_jcbPerguntaActionPerformed

        private void botaoAtualizarResposta(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_botaoAtualizarResposta
            int aux = jtMinhasPerguntas.getSelectedRow();
            if (aux != linhaTabelaPerguntaSendoUtilizada) {
                linhaTabelaPerguntaSendoUtilizada = aux;
                jtMinhasPerguntasMouseClicked(null);
            }            // TODO add your handling code here:
        }//GEN-LAST:event_botaoAtualizarResposta

        private void jtRespostaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtRespostaKeyReleased
            int aux = jtResposta.getSelectedRow();
            if (aux != linhaTabelaRespostaEmUso) {
                linhaTabelaRespostaEmUso = aux;
                jtRespostaMouseClicked(null);
            }
        }//GEN-LAST:event_jtRespostaKeyReleased

        private void jbtPesquisarRabkingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtPesquisarRabkingActionPerformed
            DefaultTableModel tableModel = (DefaultTableModel) jtbRanking.getModel();
            for (int i = tableModel.getRowCount(); i > 0; i--) {
                tableModel.removeRow(0);
            }
            if ((jcbRanking.getSelectedItem().equals("Alunos"))) {
                ArrayList<Usuario> usuarios = null;
                if (jRadioButton1.isSelected()) {
                    try {
                        Datas datas = new Datas();
                        ArrayList<Integer> splitDate = datas.splitDate(jftDateRanking.getText(), jftRankingDateFinal.getText());
                        usuarios = protocoloMensagem.decodificarUsuarios(enviarReceberPergunta(protocoloMensagem.getUsuariosNota(splitDate.get(0), splitDate.get(1), splitDate.get(2), splitDate.get(3), splitDate.get(4), splitDate.get(5))));
                    } catch (ExceptionDate ex) {
                        JOptionPane.showMessageDialog(null, ex.getMessage());
                    } catch (DatasMenorErrado ex) {
                        JOptionPane.showMessageDialog(null, ex.getMessage());
                    }
                } else {
                    usuarios = protocoloMensagem.decodificarUsuarios(enviarReceberPergunta(protocoloMensagem.getUsuariosNota()));
                }
                if (usuarios != null) {
                    for (Usuario usuario : usuarios) {
                        Vector vector = new Vector();
                        vector.add(usuario.getNomeCompleto());
                        vector.add(usuario.getPontosExtra());
                        tableModel.addRow(vector);
                    }
                }
            } else {

                List<Resposta> decodificaRespostas = null;
                if (jRadioButton1.isSelected()) {
                    try {
                        Datas datas = new Datas();
                        ArrayList<Integer> splitDate = datas.splitDate(jftDateRanking.getText(), jftRankingDateFinal.getText());
                        decodificaRespostas = protocoloMensagem.decodificarRespostas(enviarReceberPergunta(protocoloMensagem.getRespostasNota(splitDate.get(0), splitDate.get(1), splitDate.get(2), splitDate.get(3), splitDate.get(4), splitDate.get(5))));
                    } catch (ExceptionDate ex) {
                        JOptionPane.showMessageDialog(null, ex.getMessage());
                    } catch (DatasMenorErrado ex) {
                        JOptionPane.showMessageDialog(null, ex.getMessage());
                    }
                } else {
                    decodificaRespostas = protocoloMensagem.decodificarRespostas(enviarReceberPergunta(protocoloMensagem.getRespostasNota()));
                }
                if (decodificaRespostas != null) {
                    for (Resposta resposta1 : decodificaRespostas) {
                        Vector vector = new Vector();
                        vector.add(resposta1.getMensagem());
                        vector.add(resposta1.getPontuacao());
                        vector.add(resposta1.getUsuario().getNomeCompleto());
                        tableModel.addRow(vector);
                    }
                }
            }
        }//GEN-LAST:event_jbtPesquisarRabkingActionPerformed

        private void jcbRankingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbRankingActionPerformed

            DefaultTableModel tableModel = (DefaultTableModel) jtbRanking.getModel();
            if ((jcbRanking.getSelectedItem().equals("Alunos"))) {
                String[] aluno = {"Aluno", "Pontuação"};
                tableModel.setColumnIdentifiers(aluno);
            } else {
                jtbRanking.addColumn(new TableColumn());
                String[] resposta = {"Resposta", "Pontuação"};
                tableModel.setColumnIdentifiers(resposta);
            }
        }//GEN-LAST:event_jcbRankingActionPerformed

        private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
            DefaultTableModel table = (DefaultTableModel) jtbMinhasPerguntasRespostas.getModel();
            jtpComentarioAba1.setText("");
            jtpPerguntaAba1.setText("");
            for (int i = table.getRowCount(); i > 0; i--) {
                table.removeRow(0);
            }
            if (jcbPerguntaOurResposta.getSelectedItem().equals("Respostas")) {

                String[] colunasPerguntas = {"Resposta", "Comentario", "Pontuaçao"};
                table.setColumnIdentifiers(colunasPerguntas);
                ArrayList<Object> decodificaRespostasByStatus = protocoloMensagem.decodificaRespostasByStatus(enviarReceberPergunta(protocoloMensagem.getMinhasRespostasByStatus(usuario.getMatricula(), jcbCondicaoPerguntaResposta.getSelectedIndex())));
                if (decodificaRespostasByStatus != null) {
                    ArrayList<Resposta> respostasRetorno = (ArrayList<Resposta>) decodificaRespostasByStatus.get(0);
                    for (Resposta resposta : respostasRetorno) {
                        Vector v = new Vector();
                        v.add(resposta.getMensagem());
                        v.add(resposta.getComentario());
                        v.add(resposta.getPontuacao());
                        table.addRow(v);
                    }
                }
                jLabel20.setText("Resposta");
            } else {
                String[] colunasPerguntas = {"Assunto", "Pergunta", "Comentario"};
                table.setColumnIdentifiers(colunasPerguntas);
                jLabel20.setText("Pergunta");
                ArrayList<Object> decodificaRespostasByStatus = protocoloMensagem.decodificarPerguntasByStatus(enviarReceberPergunta(protocoloMensagem.getMinhasPerguntasByStatus(usuario.getMatricula(), jcbCondicaoPerguntaResposta.getSelectedIndex())));
                if (decodificaRespostasByStatus != null) {
                    ArrayList<Pergunta> perguntasRetorno = (ArrayList<Pergunta>) decodificaRespostasByStatus.get(0);
                    for (Pergunta pergunta : perguntasRetorno) {
                        Vector v = new Vector();
                        v.add(pergunta.getTitulo());
                        v.add(pergunta.getMensagem());
                        v.add(pergunta.getComentario());
                        table.addRow(v);
                    }
                }
                //enviarReceberPergunta(protocoloMensagem.getMinhasRespostasByStatus(usuario.getMatricula(), jcbCondicaoPerguntaResposta.getSelectedIndex()));
            }
        }//GEN-LAST:event_jButton6ActionPerformed

        private void jcbPerguntaOurRespostaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbPerguntaOurRespostaActionPerformed
            jcbCondicaoPerguntaResposta.removeAllItems();
            if (jcbPerguntaOurResposta.getSelectedItem().equals("Respostas")) {
                for (int i = 0; i < statusResposta.length; i++) {
                    jcbCondicaoPerguntaResposta.addItem(statusResposta[i]);
                }

            } else {
                for (int i = 0; i < statusPergunta.length; i++) {
                    jcbCondicaoPerguntaResposta.addItem(statusPergunta[i]);
                }
            }
        }//GEN-LAST:event_jcbPerguntaOurRespostaActionPerformed

        private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
            String[] decodificar = null;
            jtfTotalPontos.setText("");
            if (!jrbPesquisarPorDate.isSelected()) {
                decodificar = protocoloMensagem.decodificar(enviarReceberPergunta(protocoloMensagem.getPontuacao(usuario.getMatricula())));

                if (decodificar[0].equals("SUCE")) {
                    jtfTotalPontos.setText(decodificar[1]);
                }
            } else {
                try {
                    Datas datas = new Datas();
                    ArrayList<Integer> splitDate = datas.splitDate(jFormattedTextField3.getText(), jFormattedTextField4.getText());
                    decodificar = protocoloMensagem.decodificar(enviarReceberPergunta(protocoloMensagem.getPontuacao(usuario.getMatricula(), splitDate.get(0), splitDate.get(1), splitDate.get(2), splitDate.get(3), splitDate.get(4), splitDate.get(5))));
                    if (decodificar[0].equals("SUCE")) {
                        jtfTotalPontos.setText(decodificar[1]);
                    }
                } catch (ExceptionDate ex) {
                    jtfTotalPontos.setText("");
                    JOptionPane.showMessageDialog(null, ex.getMessage());
                } catch (DatasMenorErrado ex) {
                    jtfTotalPontos.setText("");
                    JOptionPane.showMessageDialog(null, ex.getMessage());
                }

            }


        }//GEN-LAST:event_jButton8ActionPerformed

        private void jrbPesquisarPorDateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbPesquisarPorDateActionPerformed
            if (!jrbPesquisarPorDate.isSelected()) {
                jFormattedTextField3.setEnabled(false);
                jFormattedTextField3.setText("");
                jFormattedTextField4.setText("");
                jFormattedTextField4.setEnabled(false);
            } else {
                jFormattedTextField4.setEnabled(true);
                jFormattedTextField3.setEnabled(true);
                jFormattedTextField3.setText("");
                jFormattedTextField4.setText("");
            }
        }//GEN-LAST:event_jrbPesquisarPorDateActionPerformed

        private void jtbMinhasPerguntasRespostasMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jtbMinhasPerguntasRespostasMouseClicked
            DefaultTableModel tableModel = (DefaultTableModel) jtbMinhasPerguntasRespostas.getModel();
            if (jcbPerguntaOurResposta.getSelectedItem().equals("Respostas")) {
                jtpPerguntaAba1.setText((String) tableModel.getValueAt(jtbMinhasPerguntasRespostas.getSelectedRow(), 1));
                jtpComentarioAba1.setText((String) tableModel.getValueAt(jtbMinhasPerguntasRespostas.getSelectedRow(), 0));
            } else {
                jtpPerguntaAba1.setText((String) tableModel.getValueAt(jtbMinhasPerguntasRespostas.getSelectedRow(), 2));
                jtpComentarioAba1.setText((String) tableModel.getValueAt(jtbMinhasPerguntasRespostas.getSelectedRow(), 1));
            }

        }//GEN-LAST:event_jtbMinhasPerguntasRespostasMouseClicked

        private void jtbMinhasPerguntasRespostasKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtbMinhasPerguntasRespostasKeyReleased
            jtbMinhasPerguntasRespostasMouseClicked(null);
        }//GEN-LAST:event_jtbMinhasPerguntasRespostasKeyReleased

        private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton1ActionPerformed
            if (!jRadioButton1.isSelected()) {
                jftDateRanking.setEnabled(false);
                jftDateRanking.setText("");
                jftRankingDateFinal.setText("");
                jftRankingDateFinal.setEnabled(false);
            } else {
                jftDateRanking.setEnabled(true);
                jftRankingDateFinal.setEnabled(true);
            }            // TODO add your handling code here:
        }//GEN-LAST:event_jRadioButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }// GEN-LAST:event_jButton2ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        this.dispose();
        LoginGUI loginGui = new LoginGUI();
        loginGui.setVisible(true);
    }// GEN-LAST:event_jButton1ActionPerformed

    private void jTabbedPane1MouseClicked(java.awt.event.MouseEvent evt) {// GEN-FIRST:event_jTabbedPane1MouseClicked
        if (jTabbedPane1.getSelectedComponent().getName() != null) {
            if (jTabbedPane1.getSelectedComponent().getName().equals("MinhasPerguntasRespostas")) {
                atualizarTablaPergunta();
            }
        }

    }// GEN-LAST:event_jTabbedPane1MouseClicked

    private void atualizarTablaPergunta() {
        // Popula o jTable com os dados do hibernate
        jbtResponder.setEnabled(false);
        DefaultTableModel tablePregunta = (DefaultTableModel) jtMinhasPerguntas.getModel();
        DefaultTableModel tableRespostas = (DefaultTableModel) jtResposta.getModel();
        // Limpa a tabela
        for (int i = tablePregunta.getRowCount(); i > 0; i--) {
            tablePregunta.removeRow(0);
        }
        for (int i = tableRespostas.getRowCount(); i > 0; i--) {
            tableRespostas.removeRow(0);
        }
        jtaPergunta.setText("");
        jtaResposta.setText("");
        //TODO Fazer metodo Para Receber todas as Perguntas
        ArrayList<Object> objetos = null;
        boolean isMinhaPerguntas = jcbPergunta.getSelectedIndex() != 0;
        String respondida = (String) jcbRespondidas.getSelectedItem();
        respondida = respondida.substring(0, 1);
        String frequencia = (String) jcbFrequencia.getSelectedItem();
        frequencia = frequencia.substring(0, 1);
        //  System.out.println(protocoloMensagem.getPerguntas(
        //        usuario.getMatricula(), this.numeroInicio, UsuarioGUI.numerodePerguntasRequeridas, isMinhaPerguntas, respondida, frequencia));
        //TODO Criar Metodo que passa a classificação das Perguntas.
        objetos = protocoloMensagem.decodificarPerguntas(this.enviarReceberPergunta(protocoloMensagem.getPerguntas(
                usuario.getMatricula(), this.numeroInicio, UsuarioGUI.numerodePerguntasRequeridas, isMinhaPerguntas, respondida, frequencia)));


        if (objetos != null) {
            perguntas = (List<Pergunta>) objetos.get(0);
            int maiorId = (Integer) objetos.get(1);
            int total = (Integer) objetos.get(2);
            for (Pergunta pergunta : perguntas) {
                Vector vector = new Vector();
                vector.add(pergunta.getTitulo());
                vector.add(pergunta.getMensagem());
                vector.add(statusPergunta[pergunta.getStatus()]);
                vector.add(pergunta.getUsuario().getNomeCompleto());
                tablePregunta.addRow(vector);

            }
        }
    }

    private void jTabbedPane1StateChanged(javax.swing.event.ChangeEvent evt) {// GEN-FIRST:event_jTabbedPane1StateChanged
        // TODO add your handling code here:
    }// GEN-LAST:event_jTabbedPane1StateChanged

    private void btPerguntarActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_btPerguntarActionPerformed
        String mensagemRecebida[];
        if (!jtaEnviarPergunta.getText().equals("") && !jtfTitulo.getText().equals("")) {
            try {
                mensagemRecebida = protocoloMensagem.decodificar(enviarReceberPergunta(protocoloMensagem.codificarEnviarPergunta(jtfTitulo.getText(),
                        jtaEnviarPergunta.getText(),
                        this.getMatriculaUsuario())));
                if (mensagemRecebida[0].equals("ERRO")) {
                    JOptionPane.showMessageDialog(this, "Erro: "
                            + mensagemRecebida[1]);
                } else {// Sucesso
                    if (mensagemRecebida[0].equals("SUCE")) {
                        JOptionPane.showMessageDialog(this,
                                "Pergunta enviada com sucesso");
                        jtfTitulo.setText("");
                        jtaEnviarPergunta.setText("");
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            JOptionPane.showMessageDialog(this,
                    "Preencha todos os campos para enviar a pergunta.");
        }
    }// GEN-LAST:event_btPerguntarActionPerformed

    private void btAlterarSenhaActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_btAlterarSenhaActionPerformed
        if (VerificaLogin.isSenhaIgual(pfNovaSenha.getText(),
                pfNovaSenhaRepita.getText())) {
            String[] mensagemRecebida = protocoloMensagem.decodificar(enviarReceberPergunta(protocoloMensagem.codificarAlterarSenha(usuario.getMatricula(),
                    util.VerificaLogin.gerarMD5(pfNovaSenha.getText()), util.VerificaLogin.gerarMD5(pfSenhaAntiga.getText()))));
            if (mensagemRecebida[0].equals("SUCE")) {
                JOptionPane.showMessageDialog(null,
                        "Senha Alterada com sucesso");
                pfNovaSenha.setText("");
                pfNovaSenhaRepita.setText("");
                pfSenhaAntiga.setText("");
            } else {
                if (mensagemRecebida[0].equals("ERRO")) {
                    JOptionPane.showMessageDialog(null, mensagemRecebida[1]);
                }
            }
        }
    }// GEN-LAST:event_btAlterarSenhaActionPerformed

    private void btAtualizarActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_btAtualizarActionPerformed
    }// GEN-LAST:event_btAtualizarActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jButton4ActionPerformed
        String nome = jTextField3.getText();
        String email = jTextField6.getText();
        if (!(nome.equals("") || email.equals(""))) {
            usuario.setNomeCompleto(jTextField3.getText());
            usuario.setEmail(jTextField6.getText());
            String[] decodificar = protocoloMensagem.decodificar(enviarReceberPergunta(protocoloMensagem.alterarUsuario(usuario.getMatricula(), usuario.getSenha(), usuario.getEmail(), usuario.getNomeCompleto())));
            if (decodificar[0].equals("SUCE")) {
                jLabel3.setText(nome);
                JOptionPane.showMessageDialog(null, "Dados Alterado com sucesso");

            }
        }

    }// GEN-LAST:event_jButton4ActionPerformed

    private void jbtProximasPerguntasActionPerformed(
            java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jbtProximasPerguntasActionPerformed
        atualizarTablaPergunta();
    }// GEN-LAST:event_jbtProximasPerguntasActionPerformed

    private void jbtAnteriorPerguntas1ActionPerformed(
            java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jbtAnteriorPerguntas1ActionPerformed
        // TODO add your handling code here:
    }// GEN-LAST:event_jbtAnteriorPerguntas1ActionPerformed

    /*
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new UsuarioGUI("123", "localhost", LoginGUI.PORTA).setVisible(true);
            }
        });
    }
    // */
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btAlterarSenha;
    private javax.swing.JButton btPerguntar;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton8;
    private javax.swing.JFormattedTextField jFormattedTextField3;
    private javax.swing.JFormattedTextField jFormattedTextField4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel11;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JPopupMenu jPopupMenu1;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JScrollPane jScrollPane7;
    private javax.swing.JScrollPane jScrollPane8;
    private javax.swing.JScrollPane jScrollPane9;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField6;
    private javax.swing.JTextField jTextField7;
    private javax.swing.JButton jbtPesquisarRabking;
    private javax.swing.JButton jbtResponder;
    private javax.swing.JComboBox jcbCondicaoPerguntaResposta;
    private javax.swing.JComboBox jcbFrequencia;
    private javax.swing.JComboBox jcbPergunta;
    private javax.swing.JComboBox jcbPerguntaOurResposta;
    private javax.swing.JComboBox jcbRanking;
    private javax.swing.JComboBox jcbRespondidas;
    private javax.swing.JFormattedTextField jftDateRanking;
    private javax.swing.JFormattedTextField jftRankingDateFinal;
    private javax.swing.JRadioButton jrbPesquisarPorDate;
    private javax.swing.JTable jtMinhasPerguntas;
    private javax.swing.JTable jtResposta;
    private javax.swing.JTextPane jtaEnviarPergunta;
    private javax.swing.JTextPane jtaPergunta;
    private javax.swing.JTextPane jtaResposta;
    private javax.swing.JTable jtbMinhasPerguntasRespostas;
    private javax.swing.JTable jtbRanking;
    private javax.swing.JTextField jtfEmail;
    private javax.swing.JTextField jtfMatricula;
    private javax.swing.JTextField jtfNome;
    private javax.swing.JTextField jtfTitulo;
    private javax.swing.JTextField jtfTotalPontos;
    private javax.swing.JTextPane jtpComentarioAba1;
    private javax.swing.JTextPane jtpPerguntaAba1;
    private javax.swing.JPasswordField pfNovaSenha;
    private javax.swing.JPasswordField pfNovaSenhaRepita;
    private javax.swing.JPasswordField pfSenhaAntiga;
    // End of variables declaration//GEN-END:variables

    private void iniciarUsuario(String matriculaUsuario) {
        this.usuario = new Usuario();
        //System.out.println(this.enviarReceberPergunta(protocoloMensagem.getUsuario(matriculaUsuario)));
        String[] mensagemRecebida = protocoloMensagem.decodificar(this.enviarReceberPergunta(protocoloMensagem.getUsuario(matriculaUsuario)));
        if (mensagemRecebida[0].equals("USUARIO")) {

            usuario.setMatricula(matriculaUsuario);
            usuario.setEmail(mensagemRecebida[2]);
            usuario.setNomeCompleto(mensagemRecebida[1]);
        } else {
            if (mensagemRecebida[0].equals("ERRO")) {
                JOptionPane.showMessageDialog(this, "Erro: "
                        + mensagemRecebida[1]);
            }
        }

    }

    private String enviarReceberPergunta(String mensagem) {

        try {

            Socket clientSocket = new Socket(hostname,
                    porta);
            DataOutputStream outToServer = new DataOutputStream(
                    clientSocket.getOutputStream());
            DataInputStream inFromServidor = new DataInputStream(
                    clientSocket.getInputStream());
            outToServer.writeUTF(mensagem);
            return inFromServidor.readUTF();
        } catch (java.net.ConnectException ex) {
            JOptionPane.showMessageDialog(null,
                    "Não foi possivel a Conexão com o Servidor");

        } catch (UnknownHostException ex) {
            Logger.getLogger(UsuarioGUI.class.getName()).log(Level.SEVERE,
                    null, ex);
        } catch (IOException ex) {
            Logger.getLogger(UsuarioGUI.class.getName()).log(Level.SEVERE,
                    null, ex);
        }
        return null;
    }

    public String getMatriculaUsuario() {
        return usuario.getMatricula();
    }
}
